var ProductOfNumbers = function () {
  this.queue = []
  this.list = []
};

/** 
* @param {number} num
* @return {void}
*/
ProductOfNumbers.prototype.add = function (num) {
  this.queue.push(num)
};
ProductOfNumbers.prototype.getProduct = function (k) {
  let result = 1
  // 获取最后两个数
  if (k === 1) {
    return this.queue[this.queue.length - 1]
  } else {
    for (let i = 1; i <= k; i++) {
      this.list.unshift(this.queue[this.queue.length - i])
    }
    console.log(this.list);
    while (this.list.length > 0) {
      result = result * this.list.shift()
    }
    return result
  }
};

let param = new ProductOfNumbers()
param.add(3)
param.add(0)
param.add(2)
param.add(5)
param.add(4)
console.log(param.getProduct(4));
param.add(8)
console.log(param.getProduct(2));
